﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using RFIDStockManagement.Common.Public.InterFace;
using DevExpress.XtraEditors;
using DevExpress.XtraNavBar;
using RFIDStockManagement.BLL;

namespace RFIDStockManagement.Client
{
    public partial class MainForm : BaseForm, ISwitchMainForm
    {
        private bool isRealColse;
        private RUser _curUser;

        public MainForm(RUser logUser)
        {
            if (logUser == null)
            {
                MessageBox.Show("当前登录用户信息错误,请重新登录!","登录错误");
                this.SwitchCloseForm();
            }

            if (!logUser.IsLogin)
            {
                MessageBox.Show("当前登录用户信息错误,请重新登录!", "登录错误");
                this.SwitchCloseForm();
            }

            _curUser = logUser;

            InitializeComponent();
            isRealColse = true;
        }

        #region 窗体事件

        private void MainForm_Load(object sender, EventArgs e)
        {
            BindNavigationBar();
            FormSizeChanged();
        }
        private void MainForm_SizeChanged(object sender, EventArgs e)
        {
            FormSizeChanged();
        }

        #endregion

        #region ISwitchMainForm 成员

        public bool IsRealCloseForm
        {
            get
            {
                return isRealColse;
            }
            set
            {
                isRealColse = value;
            }
        }

        public void RealCloseForm()
        {
            isRealColse = true;
            this.Close();
        }

        public void SwitchCloseForm()
        {
            isRealColse = false;
            this.Close();
        }

        #endregion

        private void lnkLoginOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //if (AlertForm.Confirm("确定登出吗？"))
            //{
                //_curUser.Logout();
                //this.RealCloseForm();
            //}
            this.Close();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (AlertForm.Confirm("确定登出吗？"))
            {
                _curUser.Logout();
            }
            else
            {
                e.Cancel = true;
            }
        }




    }
}